{#**
 * 2007-2020 PrestaShop SA and Contributors
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <contact@prestashop.com>
 * @copyright 2007-2020 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 *#}

{% import '@PrestaShop/Admin/macros.html.twig' as ps %}

{% block form %}
  {{ form_start(currencyForm, {
    'attr': {
      'id': 'currency_form',
      'data-reference-url': path('admin_currencies_get_reference_data', {'currencyIsoCode': 'CURRENCY_ISO_CODE'})|replace({'/CURRENCY_ISO_CODE': '{/id}'}),
      'data-languages': languages|json_encode|replace("'", "&#39;")|raw,
      'data-translations': {
        'step.symbol': '1. Enter symbol'|trans({}, 'Admin.International.Feature'),
        'step.format': '2. Choose format'|trans({}, 'Admin.International.Feature'),
        'modal.title': 'Customize symbol and format'|trans({}, 'Admin.International.Feature'),
        'modal.apply': 'Apply'|trans({}, 'Admin.Actions'),
        'modal.cancel': 'Cancel'|trans({}, 'Admin.Actions'),
        'modal.close': 'Close'|trans({}, 'Admin.Actions'),
        'list.language': 'Language'|trans({}, 'Admin.Global'),
        'list.example': 'Example'|trans({}, 'Admin.Global'),
        'list.edit': 'Edit symbol / format'|trans({}, 'Admin.International.Feature'),
        'list.reset': 'Reset'|trans({}, 'Admin.Actions'),
        'list.reset.success': 'Your symbol and format customizations have been successfully reset for this language.'|trans({}, 'Admin.Notifications.Success'),
        'list.example.format': '%price%'|trans({}, 'Admin.International.Feature'),
        'modal.restore.title': 'Are you sure you want to restore default settings?'|trans({}, 'Admin.International.Feature'),
        'modal.restore.apply': 'Restore'|trans({}, 'Admin.Actions'),
        'modal.restore.cancel': 'Cancel'|trans({}, 'Admin.Actions'),
        'modal.restore.body': 'Restoring your currency\'s default settings will delete all the customizations you made before. Parameters will look just the same as when the currency is freshly imported.'|trans({}, 'Admin.International.Feature')
      }|json_encode|replace("'", "&#39;")|raw
    }
  }) }}

  <div class="card card-currency">
    <div class="card-header">
      {{ 'Currencies'|trans({}, 'Admin.Global') }}
    </div>
    <div class="card-block row">
      <div class="card-text">
        {{ form_errors(currencyForm) }}

        {% if not currencyForm.vars.data.id is defined %}
          {% set selectIsoCodeHelp %}
            {{ 'By default, PrestaShop comes with a list of official currencies. If you want to use a local currency, you will have to add it manually. For example, to accept the Iranian Toman on your store, you need to create it before.'|trans({}, 'Admin.International.Help') }}
          {% endset %}
          {{ ps.form_group_row(currencyForm.selected_iso_code, {}, {
            'label': 'Select a currency'|trans({}, 'Admin.International.Feature'),
            'help': selectIsoCodeHelp
          }) }}

          {{ ps.form_group_row(currencyForm.unofficial, {}, {
            'label': 'or'|trans({}, 'Admin.Global'),
          }) }}
        {% endif %}

        {{ ps.form_group_row(currencyForm.names, {}, {
          'label': 'Currency name'|trans({}, 'Admin.International.Feature'),
        }) }}

        {% set symbolsClass = currencyForm.symbols.vars.errors|length ? '' : 'd-none' %}
        {{ ps.form_group_row(currencyForm.symbols, {}, {
          'label': 'Symbol'|trans({}, 'Admin.International.Feature'),
          'class': symbolsClass
        }) }}

        {{ ps.form_group_row(currencyForm.iso_code, {}, {
          'label': 'ISO code'|trans({}, 'Admin.International.Feature'),
          'help': 'ISO 4217 code (e.g. USD for Dollars, EUR for Euros, etc.)'|trans({}, 'Admin.International.Help')
        }) }}

        {% set exchangeRateHelp %}
          {{ 'Exchange rates are calculated from one unit of your shop\'s default currency. For example, if the default currency is euros and your chosen currency is dollars, type "1.20" (1&euro; = $1.20).'|trans({}, 'Admin.International.Help') }}
        {% endset %}

        {{ ps.form_group_row(currencyForm.exchange_rate, {}, {
          'label': 'Exchange rate'|trans({}, 'Admin.International.Feature'),
          'help': exchangeRateHelp
        }) }}

        {{ ps.form_group_row(currencyForm.precision, {}, {
          'label': 'Decimals'|trans({}, 'Admin.International.Feature')
        }) }}

        {{ ps.form_group_row(currencyForm.active, {}, {
          'label': 'Status'|trans({}, 'Admin.Global'),
        }) }}

        {{ ps.form_group_row(currencyForm.transformations, {}, {'class': 'd-none'}) }}

        {% if isShopFeatureEnabled %}
          {{ ps.form_group_row(currencyForm.shop_association, {}, {
            'label': 'Shop association'|trans({}, 'Admin.Global'),
          }) }}
        {% endif %}

        {% block currency_form_rest %}
          {{ form_rest(currencyForm) }}
        {% endblock %}
      </div>
    </div>

    <div class="card-footer">
      <div class="card-footer-left">
        <a href="{{ path('admin_currencies_index') }}" class="btn btn-outline-secondary">
          {{ 'Cancel'|trans({}, 'Admin.Actions') }}
        </a>

        {% if currencyForm.vars.data.id is defined and not currencyForm.vars.data.unofficial %}
          <button type="button" id="currency_reset_default_settings" class="btn btn-outline-primary card-currency-reset">
            <i class="material-icons">refresh</i>
            {{ 'Restore default settings'|trans({}, 'Admin.International.Feature') }}
          </button>
        {% endif %}
      </div>
      
      <button type="submit" class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
    </div>

  </div>
  {{ form_end(currencyForm) }}

  <!-- Modal -->
  <div class="modal fade" id="currency_loading_data_modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLongTitle">{{ 'Loading currency data'|trans({}, 'Admin.International.Feature') }}</h5>
        </div>
        <div class="modal-body">
          {{ 'Please wait while currency data is being loaded'|trans({}, 'Admin.International.Feature') }}
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary spinner">{{ 'Close'|trans({}, 'Admin.Actions') }}</button>
        </div>
      </div>
    </div>
  </div>
{% endblock %}
